import {Component, Inject, OnInit} from '@angular/core';
import {_HttpClient} from '@delon/theme';
import {UtilityService} from '../../../../../../service/utils.service';
import {appConfig} from '../../../../../../service/common';
import {NzModalService, NzNotificationService} from 'ng-zorro-antd';
import {ActivatedRoute, Router} from '@angular/router';
import {DA_SERVICE_TOKEN, ITokenService} from '@delon/auth';
import {SprofilesModule} from '../../../../../../service/delivent/sprofilesModule';

@Component({
  selector: 'app-profileDetail',
  templateUrl: './profileDetail.component.html',
   styleUrls: ['./profileDetail.component.less']
})
export class ProfileDetailComponent implements OnInit {

    constructor(
        private http: _HttpClient,
        private router: Router,
        private utilityService: UtilityService,
        private modal: NzModalService,
        private nznot: NzNotificationService,
        public activatedRoute: ActivatedRoute,
        @Inject(DA_SERVICE_TOKEN) private tokenService: ITokenService,
    ) { }

  profilesGuid: string; // 工作项guid
  data: any; // 工作项日期
  profiles: SprofilesModule = new SprofilesModule();
  token:any;
SelectedIndex = 0;
   tabs = [
            {
            name   : '概览',
            router : 'profilesView/overview'
            },
            {
            name   : '已投工作项',
             router : 'profilesView/Work'
            },
            {
            name   : '工作项统计',
             router : 'profilesView/deliveryDay'
            }

  ];
  id:string;
    ngOnInit() {
     this.token  = this.tokenService.get().seniortoken; // 绑定token
     this.activatedRoute.queryParams.subscribe(queryParams => {
            this.id = queryParams.guid;
        });
      if(this.id && this.id != undefined){
             localStorage.setItem('profilesGuid', this.id);
       }else{
           this.id = localStorage.getItem('profilesGuid');// 运行环境ID本地存储
       }
       this.profilesGuid = this.id;

        // this.router.navigate(['profilesView/overview', this.profilesGuid]); // 默认跳转第一个路由
           this.getRouter(  {
            name   : '概览',
            router : 'profilesView/overview',
            index : 0
        })
      this.getData()

 }
 isCollapsed = false;
    widthLeft = 8;
    widthRight = 16;
    isShow = true;
    text='收起'
  toggleCollapsed(): void {
    this.isShow = !this.isShow;
    if(this.isShow === true){
        this.widthLeft = 8;
        this.widthRight = 16;
        this.text = '收起'
    }else{
         this.widthLeft = 2;
        this.widthRight = 22;
          this.text = '展开'
    }
  }
workitemCount:any;// 工作项总数
workTypeCount:any; // 工作项类型
deliveryResultCountDetails:any; // 按投放申请状态分类统计(饼状图)
deliveryCount:any; // 已成功投放申请总数
branch:any; //分支
    getData() {

     let url = '/sProfiles/'+this.profilesGuid+'/general'
        this.utilityService.getData(appConfig.testUrl  + url )
            .subscribe(
                (val) => {

                    this.profiles = val.result.profiles;
                    this.profiles.packTiming = JSON.parse(this.profiles.packTiming);
                    this.profiles.workitemCount = val.result.workitemCount;
                    this.profiles.workTypeCount = val.result.workTypeCount;
                    this.profiles.branch = val.result.branch.fullPath;
                    this.profiles.deliveryCount = val.result.deliveryCount;
                   
                    if(val.result.isRepeal === 'true'){
                        this.profiles.isRepeal = '已运行'
                    }else{
                       this.profiles.isRepeal = '已关闭'
                    }
                    this.profiles.isRepeal
              console.log(this.profiles);


        },(error)=>{

                 this.nznot.create('error', error.code , error.msg);
        });
    }
    getRouter(it){
        console.log(it);
          this.SelectedIndex = it.index;
      this.router.navigate([ this.tabs[it.index].router,this.profilesGuid]);

     }
}
